//
//  ZLWProductDetailController.m
//  EPA
//
//  Created by lanou3g on 16/4/26.
//  Copyright © 2016年 zlw. All rights reserved.
//

#import "ZLWProductDetailController.h"
#import "ZLWUserInfoManager.h"

@interface ZLWProductDetailController ()<UIWebViewDelegate>

@end

@implementation ZLWProductDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNetWorking];
//    NSLog(@"[[ZLWUserInfoManager shareManager] auth] == %@",[[ZLWUserInfoManager shareManager] auth]);
//    NSLog(@"self.getmodel.contentid _____________%@",self.getmodel.contentid);
    // Do any additional setup after loading the view.
}

-(void)loadNetWorking
{
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
    webView.delegate = self;
    
    [ZLW_NetWorkRequestManager requestURL:[NSURL URLWithString:SHOPDTAILLIST_URL] Method:CK_POST Params:@{@"auth":[ZLWUserInfoManager shareManager].auth,@"client":@1,@"contentid":self.getmodel.contentid,@"deviceid":@"6D4DD967-5EB2-40E2-A202-37E64F3BEA31",@"version":@"3.0.6"} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
            NSDictionary *dataDict = jsonDict[@"data"][@"postsinfo"];
            dispatch_async(dispatch_get_main_queue(), ^{
           [webView loadHTMLString:dataDict[@"html"] baseURL:nil];
          
            });
        }
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//将图片大小弄成固定的
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [webView stringByEvaluatingJavaScriptFromString:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth;"
     "var maxwidth=380;" //缩放系数
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images[i];"
     "if(myimg.width > maxwidth){"
     "oldwidth = myimg.width;"
     "myimg.width = maxwidth;"
     "myimg.height = myimg.height * (maxwidth/oldwidth);"
     "}"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
